package com.baizhi.controller.person;

import com.baizhi.entity.Person;
import com.baizhi.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("person")
public class PersonController {
    @Autowired
    private PersonService personService;
    @RequestMapping("show")
    public String show(Model model){

        List<Person> people = personService.selectPersons();
        model.addAttribute("people",people);
        return "forward:/person/show.jsp";
    }
    @RequestMapping("add")
    public String add(Person person){
        personService.insertPerson(person);
        return "redirect:/person/show.do";
    }
    @RequestMapping("update")
    public String update(Integer id,Model model){
        Person person = personService.selectById(id);
        model.addAttribute("st",person);
        return "forward:/person/update.jsp";
    }
    @RequestMapping("gx")
    public  String gx(Person person){
        personService.updatePerson(person);
        return "redirect:/person/show.do";
    }
    @RequestMapping("remove")
    public String remove(Integer id){
        personService.deleteById(id);
        return  "redirect:/person/show.do";
    }
    @RequestMapping("removeP")
    public String removeP(@RequestParam("ids") List<Integer> ids) {
        System.out.println("批量删除");
        personService.deletes(ids);

        return "redirect:/person/show.do";
    }

}
